package com.timeDeal.servlet;


import com.timeDeal.bean.*;
import com.timeDeal.service.JiaoyiQingqiuServicce;
import com.timeDeal.service.ShijianchusouService;
import com.timeDeal.service.UserService;
import com.timeDeal.service.XuqiuService;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * Created by Administrator on 2016/7/24.
 */

public class WodeJiaoQingqiuServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String currentpage = request.getParameter("currentpage");
        UserBean loginuser = (UserBean) request.getSession().getAttribute("USER");
        currentpage = StringUtils.equals(currentpage, null) ? "1" : currentpage;
        String flag = StringUtils.defaultString(request.getParameter("flag"), "0");
        PageList pageList = new PageList();
        int cu = Integer.valueOf(currentpage);
        JiaoyiQingqiuServicce jiaoyiQingqiuServicce = new JiaoyiQingqiuServicce();
        XuqiuService xuqiuService = new XuqiuService();
        UserService userService = new UserService();
        if (StringUtils.equals(flag, "0")) {
            pageList = jiaoyiQingqiuServicce.getQingqiuByid(cu, loginuser.getYonghuid());
            for (Object o : pageList.getList()) {
                UserBean userBean = userService.getAuserByid(((JiaoyiQingqiuBean) o).getTijiaorenid());
                XuqiufabuBean xuqiufabuBean = xuqiuService.getAxuquById(((JiaoyiQingqiuBean) o).getXuqiufabuid());
                ((JiaoyiQingqiuBean) o).setXuqiufabuBean(xuqiufabuBean);
                ((JiaoyiQingqiuBean) o).setTijiaoren(userBean);
            }
            request.setAttribute("pageList", pageList);
            request.setAttribute("currentpage", currentpage);
            request.getRequestDispatcher("/user/wodejiaoyiqingqiu.jsp").forward(request, response);
        }
        else
        {
            pageList = jiaoyiQingqiuServicce.getQingqiuByidAndShijian(cu, loginuser.getYonghuid());
            ShijianchusouService shijianchusouService = new ShijianchusouService() ;
            for (Object o : pageList.getList()) {
                UserBean userBean = userService.getAuserByid(((JiaoyiQingqiuBean) o).getTijiaorenid());
                ShijianchushouBean shijianchushouBean = shijianchusouService.getAShijianChushouById(((JiaoyiQingqiuBean) o).getShijianchushouid());
                ((JiaoyiQingqiuBean) o).setShijianchushouBean(shijianchushouBean);
                ((JiaoyiQingqiuBean) o).setTijiaoren(userBean);
            }
            request.setAttribute("pageList", pageList);
            request.setAttribute("currentpage", currentpage);
            request.getRequestDispatcher("/user/shijianchushou/wodejiaoyiqingqiu.jsp").forward(request, response);
        }


    }
}
